﻿using UnityEngine;
using System.Collections;

public class RayCaster : MonoBehaviour {
	
	public Camera cam;

	void Start () {
		if(!cam)
			cam = Camera.main;
	}
	
	void Update ()
	{
		if(Input.GetMouseButtonDown(0))
		{
			Ray ray = cam.ScreenPointToRay(Input.mousePosition);
			RaycastHit hit;

			if(Physics.Raycast(ray, out hit))
			{
				if(hit.transform.tag == "Button"){
					ButtonInterface[] buttons = hit.transform.GetComponents<ButtonInterface>();
					foreach(ButtonInterface b in buttons){
						b.Click();
					}
				}
			}
		}
	}	
}
